package com.bestcem.xm.txtanls.service.dto;

import cn.hutool.core.collection.CollUtil;
import com.bestcem.xm.txtanls.service.dto.chart.PeriodTimeDTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName RecordSearchDTO
 * @Description 原话查询DTO
 * @Author jy.zhao
 * @Date 2021/5/11 14:08
 * @Version 1.0
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RecordSearchDTO {

    public RecordSearchDTO(String projectId, List<String> fieldIds, PeriodTimeDTO periodTime) {
        this.projectId = projectId;
        this.fieldIds = fieldIds;
        this.periodTime = periodTime;
    }

    public RecordSearchDTO(String projectId, List<String> fieldIds, List<String> keywords) {
        this.projectId = projectId;
        this.fieldIds = fieldIds;
        this.keywords = keywords;
    }

    /**
     * 项目id
     */
    private String projectId;

    /**
     * 分析字段id
     */
    private List<String> fieldIds;

    /**
     * 时间区间
     */
    private PeriodTimeDTO periodTime;

//    /**
//     * 聚合字段
//     */
//    private String groupBy;

    /**
     * 关键词list
     */
    private List<String> keywords;

    /**
     * 关键词拼接字符串
     */
    private String keywordRegexp;

    public void setKeywords(List<String> keywords) {
        this.keywords = keywords;
        if (CollUtil.isNotEmpty(keywords)) {
            // 拼接关键词
            String keywordRegexp = keywords.stream().filter(StringUtils::isNotBlank).collect(Collectors.joining("|"));
            if (StringUtils.isNotBlank(keywordRegexp)) {
                this.keywordRegexp = keywordRegexp;
            }
        }
    }
}
